//
//  TZHGAgricultureCircleViewController.m
//  AnXin100
//
//  Created by 王合润 on 2018/9/17.
//  Copyright © 2018年 tzhg. All rights reserved.
//

#import "TZHGAgricultureCircleViewController.h"
#import "AgriculturalMaterialsMallViewController.h"
#import "AXHomeNtsqVC.h"
#import "AXHomeZxktVC.h"
#import "AXHomeNzscVC.h"
#import "OptimizationBaseViewController.h"
@interface TZHGAgricultureCircleViewController ()<SDCycleScrollViewDelegate>

@property (nonatomic, strong) UIScrollView *mainScrollView;

@property (nonatomic ,strong) UIView *menuView;

@property (nonatomic, strong) SDCycleScrollView *headImageView;

@property (nonatomic, strong) UIView *newsView;


@end

@implementation TZHGAgricultureCircleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [PublicMonMethods settitle:@"农业圈" viewController:self];
    [self.view addSubview:self.mainScrollView];
    
}

#pragma lyaz load

- (UIScrollView *)mainScrollView {
    if (!_mainScrollView) {
        _mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49)];
        [_mainScrollView addSubview:self.headImageView];
        [_mainScrollView addSubview:self.menuView];
        [_mainScrollView addSubview:self.newsView];
        
    }
    return _mainScrollView;
}

- (SDCycleScrollView *)headImageView {
    if (!_headImageView) {
        NSArray *imageNames = @[@"m2.jpeg"];// 本地图片请填写全名
        _headImageView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 180) shouldInfiniteLoop:YES imageNamesGroup:imageNames];
        _headImageView.delegate = self;
        _headImageView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        _headImageView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    }
    return _headImageView;
}

- (UIView *)menuView {
    if (!_menuView) {
        NSArray *dataAry = @[@{@"title" : @"农资商城",
                               @"icon" : @"mall"},
                             @{@"title" : @"农堂社区",
                               @"icon" : @"community"},
                             @{@"title" : @"基地示范",
                               @"icon" : @"demonstrationBase"},
                             @{@"title" : @"技术方案",
                               @"icon" : @"technicalSolution"}];
        _menuView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_headImageView.frame), SCREEN_WIDTH, 90)];
        for (NSInteger i = 0; i < dataAry.count; i++) {
            NSDictionary *dic = dataAry[i];
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(SCREEN_WIDTH / 4 * i, 0, SCREEN_WIDTH / 4, 90);
            [btn setTitle:dic[@"title"] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor colorWithHex:0x333333] forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:14];
            [btn setImage:[UIImage imageNamed:dic[@"icon"]] forState:UIControlStateNormal];
            [btn setButtonLayout:CHButtonLayoutTitleBottom offset:0];
            btn.tag = 100 + i;
            [btn addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
            [_menuView addSubview:btn];
        }
    }
    return _menuView;
}

- (UIView *)newsView {
    if (!_newsView) {
        
        _newsView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_menuView.frame), SCREEN_WIDTH, _mainScrollView.mj_h - CGRectGetMaxY(_menuView.frame))];
        UILabel *informationLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 10, SCREEN_WIDTH, 15)];
        informationLabel.text = @"资讯";
        informationLabel.textColor = [UIColor colorWithHex:0x29B566];
        informationLabel.font = [UIFont systemFontOfSize:14];
        [_newsView addSubview:informationLabel];
        [_newsView addSubview:[self getFirstInformationView:CGRectMake(0, CGRectGetMaxY(informationLabel.frame), SCREEN_WIDTH, 110)]];
        [_newsView addSubview:[self getSecondInformationView:CGRectMake(0, CGRectGetMaxY(informationLabel.frame) + 110, SCREEN_WIDTH, 40)]];
        [_newsView addSubview:[self getLastImage:CGRectMake(0, CGRectGetMaxY(informationLabel.frame) + 150, SCREEN_WIDTH, _newsView.mj_h - CGRectGetMaxY(informationLabel.frame) - 150)]];
    
    }
    return _newsView;
}


- (UIView *)getFirstInformationView:(CGRect)frame {
    
    UIView *view = [[UIView alloc] initWithFrame:frame];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(12, 10, 90, 90)];
    imageView.image = [UIImage imageNamed:@"nyqptzs.png"];
    [view addSubview:imageView];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(112, 10, SCREEN_WIDTH - 122, 15)];
    titleLabel.textColor = [UIColor colorWithHex:0x333333];
    titleLabel.font = [UIFont systemFontOfSize:16];
    titleLabel.text = @"每个庄主都是“内容”打造高手";
    [view addSubview:titleLabel];
    
    UILabel *desLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleLabel.mj_x, CGRectGetMaxY(titleLabel.frame) + 2, titleLabel.mj_w, 90 - CGRectGetMaxY(titleLabel.frame) - 2)];
    desLabel.textColor = [UIColor colorWithHex:0x666666];
    desLabel.font = [UIFont systemFontOfSize:14];
    desLabel.text = @"随着庄园向前推进，越来越多庄主开始认识到内容重要性，很多庄主又会叹息摇头，感慨这个太难了。";
    desLabel.numberOfLines = 0;
    [view addSubview:desLabel];
    [desLabel alignTop];
    return view;
}

- (SDCycleScrollView *)getSecondInformationView:(CGRect)frame {
    
    
    // 情景三：图片配文字
    NSArray *titles = @[@"新建交流QQ群：185534916 ",
                        @"disableScrollGesture可以设置禁止拖动",
                        @"感谢您的支持，如果下载的",
                        @"如果代码在使用过程中出现问题",
                        @"您可以发邮件到gsdios@126.com"
                        ];
    
    SDCycleScrollView *cycleScrollView4 = [SDCycleScrollView cycleScrollViewWithFrame:frame delegate:self placeholderImage:nil];
    cycleScrollView4.scrollDirection = UICollectionViewScrollDirectionVertical;
    cycleScrollView4.onlyDisplayText = YES;
    
    NSMutableArray *titlesArray = [NSMutableArray new];
    [titlesArray addObject:@"纯文字上下滚动轮播"];
    [titlesArray addObject:@"纯文字上下滚动轮播 -- demo轮播图4"];
    [titlesArray addObjectsFromArray:titles];
    cycleScrollView4.titlesGroup = [titlesArray copy];
    [cycleScrollView4 disableScrollGesture];
    cycleScrollView4.backgroundColor = [UIColor whiteColor];
    return cycleScrollView4;
}

- (UIImageView *)getLastImage:(CGRect)frame {
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
    imageView.image = [UIImage imageNamed:@"sg2.jpeg"];
    return imageView;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)btnClickAction:(UIButton *)sender {
    
    if (sender.tag == 100) {
        AXHomeNzscVC *vc = [[AXHomeNzscVC alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        vc.isHeight = YES;
        [self.navigationController pushViewController:vc animated:YES];
    } else if (sender.tag == 101) {
        AXHomeNtsqVC *vc = [AXHomeNtsqVC new];
        vc.hidesBottomBarWhenPushed = YES;
        vc.isHeight = YES;
        [self.navigationController pushViewController:vc animated:YES];
    } else if (sender.tag == 103) {
        AXHomeZxktVC *vc = [AXHomeZxktVC new];
        vc.hidesBottomBarWhenPushed = YES;
        vc.isHeight = YES;
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        OptimizationBaseViewController *vc = [OptimizationBaseViewController new];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    }
//    if (sender.tag == 101) {
//        AgriculturalMaterialsClassifyViewController *vc = [[AgriculturalMaterialsClassifyViewController alloc] init];
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//    }
    
//    if (sender.tag == 102) {
//        LLSearchViewController *vc = [[LLSearchViewController alloc] init];
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//        ServiceViewController *vc = [[ServiceViewController alloc] init];
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//        AddressManagementViewController *vc = [[AddressManagementViewController alloc] init];
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
        
        
//        UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
//        backView.tag = 1000;
//        backView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
//        UIWindow *window = [UIApplication sharedApplication].keyWindow;
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
//        [window addGestureRecognizer:tap];
//        [window addSubview:backView];
//
//        Coupons *view = [[Coupons alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 300)];
//        [backView addSubview:view];
//
//        [UIView animateWithDuration:0.5 animations:^{
//            view.mj_y = SCREEN_HEIGHT - 300;
//        }];
//        BaseShowViewController *vc = [[BaseShowViewController alloc] init];
//        [self.navigationController pushViewController:vc animated:YES];
        
//        CooperationCaseViewController *vc = [[CooperationCaseViewController
//                                              alloc] init];
//        [self.navigationController pushViewController:vc animated:YES];
    
//    }
//
//    if (sender.tag == 103) {
//        TLCityPickerController *cityPickerVC = [[TLCityPickerController alloc] init];
////        [cityPickerVC setDelegate:self];
//
//        cityPickerVC.locationCityID = @"1400010000";
//        //    cityPickerVC.commonCitys = [[NSMutableArray alloc] initWithArray: @[@"1400010000", @"100010000"]];        // 最近访问城市，如果不设置，将自动管理
//        cityPickerVC.hotCitys = @[@"100010000", @"200010000", @"300210000", @"600010000", @"300110000", @"2000120000", @"1900040000", @"1900040000"];
//        cityPickerVC.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:cityPickerVC animated:YES];
//
//    }
}

- (void)tapAction {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [[window viewWithTag:1000] removeFromSuperview];
}


@end
